A jquery ui plugin to aide in building google maps within CMSMS.
This plugin is included with the CGGoogleMaps2 module for CMS Made Simple. It is a plugin written using the jquery ui widget factory to aide in building and interacting with google maps.
This plugin in conjunction with the dynamic nature of CMS Made Simple, Smarty templates, and the flexible way in which markers can be extracted from CMSMS Modules allows building flexible and dynamic maps.
This document describes the cggm2 jquery plugin and how to interact with it in pure html/javascript. It does not really touch on the behavior of the CGGoogleMaps2 module that wraps this plugin.
Usage of this plugin is simple and straight forward. There are only 3 basic steps:
The libraries can be included from a CDN, or downloaded locally and stored on your server. The required libraries are:
$('selector').cggm2(options);Test1 illustrates creating a simple map with a single point. To see how this is done, you can view the page's source code.
The cggm2 plugin has numerous methods to interact with the
map. To call a method in the plugin you use this
syntax: $('selector').cggm2('method'[,argument1[,argument2]]);
Retrieving the value of an option after construction can be achieved by calling the 'option' method, with a syntax such as:
$('selector').cggm2('option','name');
The type of the return value depends on the name of the option you are retrieving.
Adjusting an option in the plugin after construction can be done by calling the 'option' method, with a syntax such as:
$('selector').cggm2('option','name',value);
The type of the value depends upon the option you are setting. See the documentation below for the specific options. It is possible for the map to break or misbehave if invalid data is specified in an option. The map may update to represent the changed option.
You should see something like this:
<div id="map"></div>You can see a working example of building a map from static HTML in Test4.
<div class="cggm2_markers" style="display: none;">
<div class="cggm2_marker">
<input type="hidden" class="cggm2_marker_name" value="marker_1"/>
<input type="hidden" class="cggm2_marker_title" value="Calgary"/>
<input type="hidden" class="cggm2_marker_description" value="The Oil and Gas capitol of Canada"/>
<input type="hidden" class="cggm2_marker_latitude" value="51.0500"/>
<input type="hidden" class="cggm2_marker_longitude" value="-114.0667"/>
</div>
<div class="cggm2_marker">
<input type="hidden" class="cggm2_marker_name" value="marker_2"/>
<input type="hidden" class="cggm2_marker_title" value="Edmonton"/>
<input type="hidden" class="cggm2_marker_description" value="The capitol of the province of Alberta"/>
<input type="hidden" class="cggm2_marker_latitude" value="53.5333"/> <input type="hidden" class="cggm2_marker_longitude" value="-113.5000">
</div>
</div>
This method returns the google Map object used internally by the cggm2 plugin.
usage:
var map = $('#map').cggm2('getMap');
This method accepts a markerOptions object and will dynamically add a new marker to the map. Test3 illustrates example usage of this method. View the page source to see how it is used.
usage:
var marker_opts = {
name: 'test',
position: [ '-41.21212', '-112.12345' ],
title: 'Sample Marker',
description: 'This is a sample marker, with a larger description',
};
$('#map').cggm2('addMarker',marker_opts);
This method returns the google maps Marker object for the requested marker If the named marker cannot be found, false is returned. Test3 illustrates example usage of this method. View the page source to see how it is used.
usage:
var marker = $('#map').cggm2('getMarker','test');
This method returns an array of known marker names.
usage:
var marker_names = $('#map').cggm2('getMarkerList');
This method will remove the named marker from the map. Test3 illustrates example usage of this method. View the page source to see how it is used.
usage:
$('#map').cggm2('removeMarker','test');
This method will remove all markers from the map. Markers will then need to be added back with the addMarker method. Test3 illustrates example usage of this method. View the page source to see how it is used.
usage:
$('#map').cggm2('removeAllMarkers');
var points = [ '__MYLOCATION__', 'home' ];
$('#map').cggm2('getDirections',points[,callback]);
This method will scroll the map to the specified off screen marker. The zoom level will not be adjusted. You can see an example of the usage of this method in the Test3 example.
usage:
$('#map').cggm2('panToMarker','test');
This method will scroll the map to the specified marker (by name) and will display the infowindow for that marker. This method will only work if the marker specified exists, and there is a description or bubbletext for the marker.
usage:
$('#map').cggm2('showInfoWindow','test');
This method forces a resize event on the map element, and forces the zoom to be adjusted to fit all of the markers. (similar to zoom_encompass) however it does not enable zoom_encompass automatically. This method can be used to force the map to re-draw.
usage:
$('#map').cggm2('refresh');
todo
todo
todo
type: position
default: n/a
description: Optionally, specify the default center of the map on initial display. This option may be overridden by the sensor_center option (if sensor is enabled, and information is available).
example:
var opts = {
center: [ '51.1234', '-110.1234' ],
zoom: 8
};
type: string
default: The first icon in the icons list
description: The default icon to use for markers where an icon is not explicitly specified. The icon name must match one of the items specified in the icons array.
type: boolean
default: true
description: Indicates whether or not direction functionality is enabled.
type: boolean
default: true
description: Indicates whether directions should be drawn on the map.
type: string or node
default: none
description: Refers to the jquery selector or the node of a <div> that will be used to render the textual form of the directions (if any).
example:
var opts = {
directions: 1,
directions_panel: '#directions',
directions_draw: 1,
zoom: 8
};
type: string
default: metric
options: metric | imperial
description: Used when displaying or calculating directions this determines the units used for calculations.
type: array of icon objects
default: n/a
description: This option is used to define the icons that will be used to display markers on the map. If no icons are defined, google will use a standard icon for all markers.
type: function
function arguments: The callback method accepts an instance of the cggm2 plugin as its only argument.
default: none
description: This callback is used to add functionality for when the map is idle (no user interaction). It can be used to add additional dynamic functionality to the map.
example:
var opts = {
init_cb: function(cggm2) {
// an example to hide a busy icon when the map is done doing its thing
$('#loading').hide();
}
};
type: boolean
default: true
description: Toggles infowindow functionality for the entire map. Note, individual markers still need a description or bubbletext defined.
type: string
default: 'infoBox'
description: The CSS class name to use for the infowindow
type: string
default: 'click'
options: 'click' | 'mouseover'
description: Determine the event (click or mouseover) that will trigger the display of the infowindow
type: function
function arguments: none
default: n/a
description: A callback function to handle the display of the infowindow
type: function
function arguments: cggm2 object reference, marker object reference
default: n/a
description: A callback used to retrieve contents for populating the infowindow
type: array of kml objects
default: n/a
description: An array of objects representing the KML layers that should initially be displayed.
example:
var opts = {
kml: [
{
name: 'layer1',
href: 'http://www.website.com/assets/layer1.kml'
},
{
name: 'layer2',
href: 'http://www.website.com/assets/layer2.kml'
},
]
};
type: array of MarkerOption objects
default: n/a
description: An array of objects representing markers that should initially be displayed
example:
var opts = {
markers: [
{
name: 'marker_1',
title: 'Title or tooltip for marker 1',
description: 'Extended information for marker 1',
icon: 'home',
position: [ '-45.1234', '51.1234' ]
},
{
name: 'marker_2',
title: 'Title or tooltip for marker 2',
description: 'Extended information for marker 2',
icon: 'home',
position: [ '-51.1234', '45.1234' ]
}
]
}
todo
todo
todo
type: string
default: 'My Location'
description: This option controls the title used for the sensor_marker (if enabled).
type: boolean
default: true
description: This flag controls wether navigation (panning) controls are displayed on the resulting map.
type: boolean
default: true
description: This flag controls the display of scale controls
type: boolean
default: true
description: This flag indicates whether or not the map will attempt to determine the user's location using embedded GPS or other mechanisms
note: This enables the collection of geolocation data by the browser (each customer may approve, or deny the reading of geolocation data by the browser).
type: boolean
default: false
description: This flag is dependent upon the sensor flag above. If both are enabled, and the customer allows the browser to collect geolocation data then the map will be initially centered at the users location.
type: boolean
default: false
description: This flag is dependent on the sensor flag above. If both are enabled, then a marker will be placed at the users current location.
type: string
default: n/a
description: This option is dependent upon the sensor flag, and the sensor_marker flags above. This option specifies the name of the icon to use for the sensor marker. The icon name must be one of the icons specified with the icons parameter.
type: boolean
default: true
description: This flag toggles the display of streetview controls on the map.
type: boolean
default: true
description: This flag toggles the use of the tooltip plugin, as opposed to standard HTML titles for markers. If this flag is enabled, and a marker has a title, then the tooltip plugin will be used for displaying the marker title.
type: string
default: 'tooltip'
description: This option is dependent upon the tooltip flag above. If the tooltip flag is enabled then this option specifies the CSS class name of the element that will contain the tooltip.
type: string
default: 'hybrid'
options: map | satellite | terrain | hybrid
description: This option defines the initial type of map that is displayed.
type: boolean
default: true
description: This flag defines wether controls to allow changing the map type will be displayed.
type: string
default: 'default'
options: default | dropdown | small | horizontal_bar
description: This option is dependent upon the type_controls flag above. It defines the style of controls that will be displayed to allow the user to change the map type.
type: integer
default: undefined
options: 1 to 17
description: This option defines the initial zoom level of the map. The greater the number the higher the zoom level. This option may be overriden by the zoom_encompass option below.
type: boolean
default: true
description: This flag determines whether controls for zooming in and out will be visible on the map.
type: string
default: 'default'
options: default | large | small
description: This option defines the type of zoom controls that will be displayed on the map. This option is dependent upon the zoomControl option above.
type: bool
default: false
description: If this option is enabled, then the original zoom of the map will be adjusted to fit all of the known markers. Similarly, if markers are dynamically added, the zoom will be adjusted so that all markers fit inside the map. Zoom is not adjusted upon removal of markers.
In the near future I will be extending the functionality and behavior of the icon and kml related methods and options. This may result in some backward compatibility issues.
Additionally, I intend to add on to the category functionality to allow dynamically displaying markers by categories, etc.
I would like at this time to give much thanks to the jquery, and jquery-ui development team without which making this plugin would have been much more difficult (I just love jquery, it makes working in javascript almost pleasant).
Secondly, the google guys for providing a very extensive, free, and very powerful maps API.
Thirdly to the person who created the tooltip class to addon to the google maps api (author unknown, but here is a reference: http://medelbou.wordpress.com/2012/02/03/creating-a-tooltip-for-google-maps-javascript-api-v3/)
And last, but not least to the author(s) of the infobox library for google maps. (reference: http://google-maps-utility-library-v3.googlecode.com/svn/trunk/infobox/docs/reference.html).